/******************* (C) COPYRIGHT 2022 CHU WEI TENG ***********************************************
**
**------------------ File Info ---------------------------------------------------------------------
** File name:      dwin_widget.h
** modified Date:  2022-05-10
** Last Version:   V1.0
** Descriptions: 
** 
**------------------ Modfication  log --------------------------------------------------------------
** Date       Who            Rev        Comments
----------------------------------------------------------------------------------------------------
   22/05/10  chuwt@qq.com    V1.00      created

****************************************************************************************************/
#ifndef __DWIN_WIDGET_H__
#define __DWIN_WIDGET_H__

#include "dwin_types_def.h"
#include "dwin_list.h"

/* Public define-----------------------------------------------------------------------------------*/
#define        GBK_MAX_CNT      40

/* Public typedef----------------------------------------------------------------------------------*/
typedef enum 
{
    EVT_CLICK, 
    EVT_INUPT,
}dwin_widget_event_t;

typedef enum 
{
    DWIN_BUTTON,
    DWIN_EDIT,
    DWIN_EDIT_GBK,
    DWIN_LABEL,
    DWIN_LABEL_GBK,
    DWIN_PAGE,
    DWIN_WINDOWS,
	DWIN_TITLEBAR,
}dwin_widget_type_t;

typedef struct dwin_widget dwin_widget_t;

typedef struct dwin_widget_vtable dwin_widget_vtable_t;

typedef ret_t (*widget_event_func_t)(dwin_widget_t *widget);

typedef ret_t (*widget_event_dispatch_t)(dwin_widget_t *widget, void* ctx);

typedef ret_t (*widget_creat_t)(dwin_widget_t *widget, uint16_t addr, uint16_t attr, uint16_t size);

typedef struct 
{
    dwin_widget_type_t      type;
    uint16_t                addr;   
    uint16_t                attr;
    uint16_t                size;
    widget_creat_t          create;
}widget_table_type_t;

struct dwin_widget_vtable
{
    uint32_t                obj_size;
    dwin_widget_vtable_t*   parent;   
    widget_event_dispatch_t dispatch;
};

/**
 * @class dwin_widget
 * @node  控件基类
**/
struct dwin_widget
{
    dwin_list_t             list;
    dwin_widget_t*          parent;
    dwin_widget_vtable_t*   vt;
    widget_event_func_t     func;

    dwin_widget_type_t      widget_type;
    uint8_t                 active;
    uint16_t                addr;
    uint16_t                attr;
    uint16_t                size;
    void*                   data;
};

/* Public function---------------------------------------------------------------------------------*/
dwin_widget_t * dwin_widget_create(dwin_widget_t* parent, dwin_widget_vtable_t* vtable, uint16_t ex_size);
ret_t dwin_widget_free(dwin_widget_t* widget);

ret_t dwin_widget_hide(dwin_widget_t* widget, uint8_t is_hide);
ret_t dwin_widget_change_color(dwin_widget_t* widget, uint16_t color);
ret_t dwin_widget_write(dwin_widget_t* widget);
ret_t dwin_multi_widget_write(dwin_widget_t** widget_arry, uint8_t count);
ret_t dwin_widget_event_register(dwin_widget_t* widget, uint32_t event, widget_event_func_t func);

#endif
